package com.tranq;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Iterator;

public class TextDataFileLoader implements AutoCloseable, Iterator<String> {
    private BufferedReader bufferedReader;

    public TextDataFileLoader(String filename) throws FileNotFoundException {
        bufferedReader = new BufferedReader(new FileReader(filename));
    }
    @Override
    public void close() throws Exception {
        if(bufferedReader!=null){
            bufferedReader.close();
        }
    }

    @Override
    public boolean hasNext() {
        try {
            return bufferedReader.ready();
        } catch (IOException e) {
            return false;
        }
    }

    @Override
    public String next() {
        try {
            return bufferedReader.readLine();
        } catch (IOException e) {
            return "";
        }
    }
}
